package cn.wolfcode.trip.base.service.impl;

import cn.wolfcode.trip.base.domain.HotelDictionaryItem;
import cn.wolfcode.trip.base.mapper.HotelDictionaryItemMapper;
import cn.wolfcode.trip.base.query.HotelDictionaryItemQueryObject;
import cn.wolfcode.trip.base.query.QueryObject;
import cn.wolfcode.trip.base.service.IHotelDictionaryItemService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class HotelDictionaryItemServiceImpl implements IHotelDictionaryItemService {
    @Autowired
    private HotelDictionaryItemMapper hotelDictionaryItemMapper;

    @Override
    public PageInfo<HotelDictionaryItem> query(QueryObject qo) {

        PageHelper.startPage(qo.getCurrentPage(),qo.getPageSize(),qo.getOrderBy());
        List<HotelDictionaryItem> list = hotelDictionaryItemMapper.queryForList(qo);


        return new PageInfo<>(list);

    }

    @Override
    public List<HotelDictionaryItem> listItemByCityId(HotelDictionaryItemQueryObject qo) {
        return hotelDictionaryItemMapper.queryItemByCityId(qo);
    }



    @Override
    public List<HotelDictionaryItem> listByCityId(QueryObject qo) {
        return hotelDictionaryItemMapper.queryByCityId(qo);
    }


    @Override
    public void saveOrUpdate(HotelDictionaryItem hotelDictionaryItem) {
        //自动添加序列
        if (hotelDictionaryItem.getSequence()== null) {
            Integer maxSequence = hotelDictionaryItemMapper.getMaxSequence(hotelDictionaryItem.getPlace().getId());
            hotelDictionaryItem.setSequence(maxSequence == null ? 1 : maxSequence + 1);

        }
        if (hotelDictionaryItem.getId()!=null) {
            hotelDictionaryItemMapper.updateByPrimaryKey(hotelDictionaryItem);

        }else{
            hotelDictionaryItemMapper.insert(hotelDictionaryItem);
        }

    }

    @Override
    public void delete(Long id) {
        hotelDictionaryItemMapper.deleteByPrimaryKey(id);

    }

    @Override
    public HotelDictionaryItem selectByPrimaryKey(Long id) {
        return hotelDictionaryItemMapper.selectByPrimaryKey(id);
    }

    @Override
    public List<HotelDictionaryItem> selectAll() {
        return hotelDictionaryItemMapper.selectAll();
    }
}
